package com.freeter.modules.AdvPosition.controller;

import java.util.Arrays;

import com.freeter.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.freeter.common.utils.JQPageInfo;
import com.freeter.common.mpextend.parser.ParseWrapper;
import com.freeter.common.utils.PageInfo;


import com.freeter.modules.AdvPosition.entity.AdvPositionEntity;
import com.freeter.modules.AdvPosition.entity.view.AdvPositionView;
import com.freeter.modules.AdvPosition.entity.model.AdvPositionModel;

import com.freeter.modules.AdvPosition.service.AdvPositionService;
import com.freeter.common.utils.PageUtils;
import com.freeter.common.utils.R;
import com.freeter.common.utils.MPUtil;



/**
 * 
 * 后端接口
 * @author xuchen
 * @email 171998110@qq.com
 * @date 2019-09-05 10:50:55
 */
@RestController
@RequestMapping("AdvPosition/advposition")
@SuppressWarnings({"unchecked","rawtypes"})
public class AdvPositionController {
    @Autowired
    private AdvPositionService advPositionService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("AdvPosition:advposition:list")
    public PageUtils page(JQPageInfo jqPageInfo,AdvPositionModel advPosition){
        EntityWrapper< AdvPositionEntity> ew = ParseWrapper.parseWrapper(advPosition);
     	PageInfo pageInfo = new PageInfo(jqPageInfo);
     	PageUtils page = advPositionService.queryPage(pageInfo, ew);
    
        return page;
        
    }

	/**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("AdvPosition:advposition:list")
    public R list( AdvPositionModel advPosition){
       	EntityWrapper< AdvPositionEntity> ew = ParseWrapper.parseWrapper(advPosition);
        return R.ok().put("data",  advPositionService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    @RequiresPermissions("AdvPosition:advposition:info")
    public R query(AdvPositionEntity advPosition){
        EntityWrapper< AdvPositionEntity> ew = ParseWrapper.parseWrapper(advPosition);
		AdvPositionView  advPositionView =  advPositionService.selectView(ew);
		return R.ok("查询成功").put("data",  advPositionView);
    }
	
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("AdvPosition:advposition:info")
    public R info(@PathVariable("id") Integer id){
        AdvPositionEntity advPosition = advPositionService.selectById(id);

        return R.ok().put("advPosition", advPosition);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("AdvPosition:advposition:save")
    public R save(@RequestBody AdvPositionEntity advPosition){
    	ValidatorUtils.validateEntity(advPosition);
        advPositionService.insert(advPosition);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("AdvPosition:advposition:update")
    public R update(@RequestBody AdvPositionEntity advPosition){
        ValidatorUtils.validateEntity(advPosition);
        advPositionService.updateAllColumnById(advPosition);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("AdvPosition:advposition:delete")
    public R delete(@RequestBody Integer[] ids){
        advPositionService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
